package com.cloudcross.ssp.listener;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.common.Config;

/**
 * 让项目一启动就加载地域,放进内存里
 * 
 * @author wuqiang.du
 *
 */
@Service
public class InitDataListener implements ApplicationListener<ContextRefreshedEvent> {

	@Autowired
	Config config;
	
	/**
	 * 启动加载执行
	 */
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		// 这个防止被加载两次
		if (event.getApplicationContext().getParent() == null) {
			// 加载mongoDB数据库信息
			InitData.mongodbMap.put("host", config.getMongodbHost());
			InitData.mongodbMap.put("port", config.getMongodbPort());
			InitData.mongodbMap.put("user", config.getMongodbUser());
			InitData.mongodbMap.put("pass", config.getMongodbPass());
		}
	}

}
